#pragma once
#include "..\CommPort\CommPort.h"

class CCommDevice
{
public:
	CCommDevice(void);
	virtual ~CCommDevice(void);

	BOOL Open(LPCTSTR szCommPort, BYTE cAddr);
	void Close(void);

	_JIN_HANDLER<void (CCommDevice*, BYTE)>			OnCommandError;
	_JIN_HANDLER<void (CCommDevice*, BYTE)>			OnCoinIn;
	_JIN_HANDLER<void (CCommDevice*, BYTE, BYTE)>	OnCoinOut;
	_JIN_HANDLER<void (CCommDevice*, BYTE, BYTE)>	OnKeyboardEvent;

	operator HCOMMDEVICE (void) const
	{
		return m_hCommDevice;
	}

	LPCTSTR GetPortName(void)
	{
		return ::GetCommPortName(m_hCommPort);
	}
	BYTE GetAddr(void) const
	{
		return ::GetCommDeviceAddr(m_hCommDevice);
	}
	void PushCommand(CommData* pCmd)
	{
		::PushCommDeviceCommand(m_hCommDevice, pCmd);
	}

private:
	static void CALLBACK _RecvCommand(HCOMMDEVICE, CommData*, CCommDevice*);

private:
	HCOMMPORT			m_hCommPort;
	HCOMMDEVICE			m_hCommDevice;
	_JIN_FIXED_CLASS(CCommDevice);
};

